<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>招生信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">所属年份</div>
                <div class="layui-inline">
                    <select name="yearId" lay-verify="">
                        <option value="-1" >全部</option>
                        {volist name="yearList" id="vo"}
                        <option value="{$vo['attr_id']}" >{$vo['attr_name']}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">所属地区</div>
                <div class="layui-inline">
                    <select name="locationId" lay-verify="">
                        <option value="-1" >全部</option>
                        {volist name="locationList" id="vo"}
                        <option value="{$vo['attr_id']}" >{$vo['attr_name']}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-task-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>

            </div>

            <table id="table" lay-filter="table"></table>
            <script type="text/html" id="ishot">
                {{#  if(d.art_ishot == 1){ }}
                <button class="layui-btn layui-btn-xs">已热门</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">未热门</button>
                {{#  } }}
            </script>

            <script type="text/html" id="ischeck">
                {{#  if(d.art_ischeck == 1){ }}
                <button class="layui-btn layui-btn-xs">已审核</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                {{#  } }}
            </script>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.art_istop == 1){ }}
                <button class="layui-btn layui-btn-xs">是</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">否</button>
                {{#  } }}
            </script>
            <script type="text/html" id="operation">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="read"><i
                        class="layui-icon layui-icon-read"></i>查看</a>
                <a class="layui-btn layui-bg-green layui-btn-xs" lay-event="import"><i
                        class="layui-icon layui-icon-add-circle"></i>导入</a>
                <a class="layui-btn layui-bg-red layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>清除</a>
            </script>
        </div>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
    }).use(['index', 'useradmin', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;


        $("#test").click(function(){
            layer.load(0,{
                shade:false,
                time:1500
            })

        });


        table.render({
            elem: '#table'
            , url: "{:url ('admin/Information/informationCategoryList')}"
            , page: true
            , cols: [[
                {field: 'attr_id', width: 80, title: 'ID', sort: true}
                , {field: 'year', title: '年份' ,align:"center"}
                , {field: 'location', title: '地区' ,align:"center"}
                , {title: '操作', width: 300, align: 'center', fixed: 'right', toolbar: '#operation'}
            ]]
            , text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });

        //监听搜索
        form.on('submit(LAY-task-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    "yearId":field.yearId,
                    "locationId":field.locationId
                }
            });
        });

        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            var attr_id=data.attr_id;
            var location=data.attr_name;
            var year=data.attr_value;
            if(obj.event==="read"){
                layer.open({
                    type: 2
                    , title: '数据查看'
                    , content: "{:url ('admin/Information/informationDetailList')}?location="+location+"&year="+year
                    , area: ['1100px', '600px']
                    , btn: ['确定']
                    , yes: function (index, layero) {
                        layer.close(index); //关闭弹层
                    }
                });
            }
            else if (obj.event === 'import') {
                layer.open({
                    type: 2
                    , title: 'Excel导入'
                    , content: "{:url ('admin/Information/informationAddByExcel')}"
                    , area: ['800px', '370px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var loadingObj;
                        layer.close(index);
                        loadingObj=layer.msg('文件处理中，请稍等', {icon: 16,time:6*1000});

                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID)
                            , form = layero.find('iframe').contents().find('#form');

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var formData = new FormData(form[0]);
                            var field = data.field; //获取提交的字段
                            // {sen_game_content_class_id: "2", file: "", sentenceContent: ""}
                            if (field.file === "") {
                                layer.msg("请上传Excel文件", {icon: 5, time: 1500}, function () {
                                });
                                return false;
                            }
                            //拿到数据后进行ajax提交数据
                            //发起ajax请求
                            $.ajax({
                                url:"{:url ('admin/Information/informationAddByExcel')}?attr_id="+attr_id,
                                type: "post",
                                data: formData,
                                dataType: "json",
                                // async: false,
                                processData: false,
                                contentType: false,
                                beforeSend:function(){
                                    //在发送之前显示请等待
                                    //提前关闭弹窗，防止用户反复上传
                                },
                                success: function (res) {
                                    layer.close(loadingObj);
                                    if (res.code == 1) {
                                        layer.msg(res.msg, {icon: 1, time: 1500}, function () {
                                        });
                                    } else {
                                        layer.msg(res.msg, {icon: 5, time: 1500}, function () {
                                        });
                                    }
                                }
                            })

                        });
                        submit.trigger('click');
                    }
                });
            }
            else if (obj.event === 'del') {
                layer.confirm('确定清除该分类下的数据？', function (index) {
                    //分类信息
                    var data={
                       "location":location,
                        "year":year
                    };
                    $.ajax({
                        url: "{:url ('admin/Information/deleteInformation')}",
                        type: "post",
                        dataType: "json",
                        data:data,
                        success: function (res) {
                            if (res.code == 1) {
                                layer.msg(res.msg, {icon: 1, time: 1500}, function () {
                                });
                            } else {
                                layer.msg(res.msg, {icon: 5, time: 1500}, function () {
                                });
                            }
                        }
                    })
                    layer.close(index);
                });
            }
            else if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '分类信息编辑'
                    , content: "{:url ('admin/Information/informationCategoryEdit')}?attr_id="+attr_id
                    , area: ['800px', '400px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url: "{:url ('admin/Information/informationCategoryEdit')}?attr_id="+attr_id,
                                type: "post",
                                dataType: "json",
                                data:field,
                                success: function (res) {
                                    if (res.code == 1) {
                                        layer.close(index); //关闭弹层
                                        layer.msg(res.msg, {icon: 1, time: 1500}, function () {
                                            table.reload('table'); //数据刷新
                                        });
                                    } else {
                                        layer.msg(res.msg, {icon: 5, time: 1500}, function () {
                                        });
                                    }
                                }
                            })
                            return false;
                        });
                        submit.trigger('click');
                    }
                    , success: function (layero, index) {

                    }
                })
            }
        });

        //事件(table上面的添加功能)
        var active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '添加信息分类'
                    , content: "{:url ('admin/Information/informationCategoryAdd')}"
                    , area: ['800px', '400px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            let field = data.field; //获取提交的字段
                            $.ajax({
                                url: "{:url ('admin/Information/informationCategoryAdd')}",
                                type: "post",
                                data: field,
                                dataType: "json",
                                success: function (res) {
                                    if (res.code == 1) {

                                        layer.close(index); //关闭弹层
                                        layer.msg(res.msg, {icon: 1, time: 1500}, function () {
                                            table.reload('table');
                                        });
                                    } else {
                                        layer.msg(res.msg, {icon: 5, time: 1500}, function () {
                                        });
                                    }
                                }
                            })
                            return false;
                        });

                        submit.trigger('click');
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>

